package cn.gson.fengboot.controller;

import cn.gson.fengboot.aspect.MyLog;
import cn.gson.fengboot.model.pojos.Dtail;
import cn.gson.fengboot.model.pojos.Dttemplate;
import cn.gson.fengboot.model.pojos.Dtype;
import cn.gson.fengboot.model.pojos.QempFrom;
import cn.gson.fengboot.model.service.DtailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/business/tail")
public class DtailController {

    @Autowired
    DtailService service;

    /*查询该商机对应所有跟进记录*/
    @RequestMapping("/selectAllTails")
    public List<Dtail> selectAllTails(Integer busId){
        return service.selectAllTails(busId);
    }

    /*查询跟进模板*/
    @RequestMapping("/selectttemplate")
    public List<Dttemplate> selectttemplate(){
        return service.selectttemplate();
    }

    /*查询跟进类型*/
    @RequestMapping("/selectalltype")
    public List<Dtype> selectalltype(){
        return service.selectalltype();
    }

    /*添加商机跟进记录*/
    @RequestMapping("/addbustail")
    @MyLog(modul = "售前模块",desc = "添加跟进记录")
    public void addbustail(@RequestBody Dtail dtail, HttpServletRequest request){
        QempFrom emp=(QempFrom)request.getSession().getAttribute("user");
        String busPeople = emp.getEmpName();
        dtail.setTailPeople(busPeople);
        dtail.setTailNowtime(new Timestamp(new Date().getTime()));
        service.addbustail(dtail);


    }

    /*添加跟进模板*/
    @RequestMapping("/addttem")
    @MyLog(modul = "售前模块",desc = "添加跟进模板")
    public void addttem(@RequestBody Dttemplate dttemplate){
        service.addttem(dttemplate);
    }

    /*删除跟进模板*/
    @RequestMapping("/detttem")
    @MyLog(modul = "售前模块",desc = "删除跟进模板")
    public void detttem(Integer ttemplateId){
        service.detttem(ttemplateId);
    }

    /*根据跟进类型查询跟进模板*/
    @RequestMapping("/selectttembytypeId")
    public List<Dttemplate> selectttembytypeId(Integer typeId){
        return service.selectttembytypeId(typeId);
    }

}
